<?php


class Admini_ManagereportController extends Uuch_ManageController {

    public function init() {
        parent::init();
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/home/warehouse.css');
        $this->appendCss('/admins/css/common.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
        $this->view->type = "system";
    }

    public function indexAction() {
        $this->setTitle("增长率统计");
        $start = $this->getSafeParam("starttime");
        $end = $this->getSafeParam("endtime");
        if(!$start){
            $start = date("Y-m-d",strtotime("-1 month"));
        }
        if(!$end){
            $end = date("Y-m-d",strtotime("-1 month"));
        }
        $cityId = $this->getSafeParam("cityId");
        $cityItem = Application_Model_city::getUserCity($cityId);
        $report = new Application_Model_DbTable_Report();
        $this->view->memberCount = $report->getMemberCount();   //当前会员总数
        $this->view->storeWeight = $report->getStoreWeight(1);   //当前库存重量
        $showData = new Application_Model_Data();
        $this->view->starttime = $start;
        $this->view->endtime = $end;
        $this->view->cityId = $cityId;
        $this->view->cityName = $cityItem?$cityItem->Name:"";
        $this->view->showData = $showData;
        $words = array();
        for ($i = 0; $i < 26; $i++) {
            $words[] = chr(65 + $i);
        }
        $this->view->words = $words;
        $this->view->stype = 12;        
    }
    
    public function showdataAction() {
        $type = $this->getSafeParam("type");
        $starttime = $this->getSafeParam("starttime");
        $endtime = $this->getSafeParam("endtime");
        $repoty = new Application_Model_DbTable_Report();
        $state = $repoty->distinctState($type, $starttime, $endtime);
        $showData = new Application_Model_Data();
        $this->view->type = $type;
        $this->view->starttime = $starttime;
        $this->view->endtime = $endtime;
        $this->view->stateArr = $state;
        $this->view->showData = $showData;
        $this->_helper->layout->disableLayout();
    }

    public function buyshopAction(){
        $this->setTitle("代购增长率统计");
        $start = $this->getSafeParam("dateinbegin")?$this->getSafeParam("dateinbegin")." 00:00:00":"";
        $end = $this->getSafeParam("dateinend")?$this->getSafeParam("dateinend")." 23:59:59":"";
        if(!$start){
            $start = date("Y-m-d")." 00:00:00";
        }
        if(!$end){
            $end = date("Y-m-d")." 23:59:59";
        }
        $report = new Application_Model_DbTable_Report();
        $this->view->allShopBuyCount = $report->shopBuyCount($start, $end, "all");  //总代购订购数
        $this->view->orderShopBuyCount = $report->shopBuyCount($start, $end, "order");  //老会员代购订购数
        $this->view->newShopBuyCount = $report->shopBuyCount($start, $end, "new");  //新会员代购订购数
        $this->view->allShopBuyMoney = $report->shopBuyMoney($start, $end, "all");    //总代购金额
        $this->view->orderShopBuyMoney = $report->shopBuyMoney($start, $end, "order");   //老会员代购金额
        $this->view->newShopBuyMoney = $report->shopBuyMoney($start, $end, "new");   //新会员代购金额
        $this->view->allShopBuyMemberCount = $report->shopBuyMemberCount($start, $end, "all"); //代购总会员数
        $this->view->newShopBuyMemberCount = $report->shopBuyMemberCount($start, $end, "new"); //代购新会员数
        $this->view->orderShopBuyMemberCount = $report->shopBuyMemberCount($start, $end, "order"); //代购老会员数
        $this->view->amountOfThePrepaid = $report->getAllBalance("recharge", $start, $end);   //会员充值总金额
        $this->view->amountOfTheConsumption = $report->getAllBalance("expense", $start, $end);   //会员消费总金额
        $this->view->balance = $report->getAllBalance("balance", $start, $end);           //会员总余额
        $this->view->dateinbegin = $start;
        $this->view->dateinend = $end;
        $this->view->stype = 13; 
    }
    
    public function topchannelAction(){
        $this->setTitle("渠道商排名");
        $report = new Application_Model_DbTable_Report();
        $start = $this->getSafeParam("dateinbegin");
        $end = $this->getSafeParam("dateinend");
        $this->view->dateinbegin = $start;
        $this->view->dateinend = $end;
        $this->view->list = $report->topChannel($start,$end);
        $this->view->stype = 21;        
    }
    
    public function getbycityAction(){
        $report = new Application_Model_DbTable_Report();
        $start = $this->getSafeParam("startTime");
        $end = $this->getSafeParam("endTime");
        $cid = $this->getSafeParam("cid");
        $city = Application_Model_city::load($cid);
        $newSendBillCount = $report->sendBillCount($start,$end,"new",$cid);                                                 //新会员发运单次数
        $newSendBillMemberCount = $report->sendBillMemberCount($start,$end,"new",$cid);                                     //发运单新会员数
        $registeredCount = $report->registeredCount($start,$end,$cid);                                                      //注册会员数                                             
        $newStoreItemNum = $report->storeItemNum($start,$end,"new",$cid);                                                   //新会员包裹入库数
        $newShopBuyCount = $report->shopBuyCount($start, $end,"new",$cid);                                                  //新会员代购订购数
        $allShopBuyCount = $report->shopBuyCount($start, $end,"all",$cid);                                                  //所有会员代购订购数
        $newShopBuyMemberCount = $report->shopBuyMemberCount($start, $end,"new",$cid);                                      //代购新会员数                                                                                                //新会员发单金额
        $newSendBillMoney = $report->sendBillMoney($start,$end,"new",$cid)?$report->sendBillMoney($start,$end,"new",$cid):0;                     //新会员运单金额
        $newShopBuyMoney = $report->shopBuyMoney($start, $end, "new", $cid)?$report->shopBuyMoney($start, $end, "new", $cid):0;                  //新会员代购金额
        $newInstoreWeight = $report->InstoreWeight($start,$end,"new",$cid)?number_format($report->InstoreWeight($start,$end,"new",$cid),3):0;                                                                      //新会员包裹入库重量
        $this->json(array('newStoreItemNum'=>$newStoreItemNum,'registeredCount'=>$registeredCount,'newShopBuyCount'=>$newShopBuyCount,
                        'newSendBillCount'=>$newSendBillCount,'newSendBillMemberCount'=>$newSendBillMemberCount,
                        'newShopBuyMemberCount'=>$newShopBuyMemberCount,'newSendBillMoney'=>$newSendBillMoney,'newShopBuyMoney'=>$newShopBuyMoney,'newInstoreWeight'=>$newInstoreWeight,'city'=>$city->Name,'allShopBuyCount'=>$allShopBuyCount));
    }
    
}

?>

